home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-10-20 | 964 b | 62 lines | [TEXT/CWIE] |
- #include <iostream.h>
-
-
- //--------------------------------------- Rectangle
-
- class Rectangle
- {
- // Data members...
- protected:
- short height;
- short width;
-
- // Member functions...
- public:
- Rectangle( short heightParam, short widthParam );
- void DisplayArea();
- };
-
- Rectangle::Rectangle( short heightParam, short widthParam )
- {
- height = heightParam;
- width = widthParam;
- }
-
- void Rectangle::DisplayArea()
- {
- cout << "Area is: " <<
- height * width << '\n';
- }
-
-
- //--------------------------------------- Rectangle:Square
-
- class Square : public Rectangle
- {
- // Data members...
-
- // Member functions...
- public:
- Square( short side );
- };
-
- Square::Square( short side ) : Rectangle( side, side )
- {
- }
-
-
- //--------------------------------------- main()
-
- int main()
- {
- Square *mySquare;
- Rectangle *myRectangle;
-
- mySquare = new Square( 10 );
- mySquare->DisplayArea();
-
- myRectangle = new Rectangle( 10, 15 );
- myRectangle->DisplayArea();
-
- return 0;
- }